package com.taotao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.EasyUiPage;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.pojo.TbItem;
import com.taotao.service.ItemService;

@Controller
@RequestMapping("/item")
public class ItemController {
	@Autowired
	ItemService itemService;

	@RequestMapping("/findItem")
	public @ResponseBody TbItem findItem(Long id) {
		System.out.println(id);
		return itemService.findItemById(id);
	}

	@RequestMapping("/list")
	public @ResponseBody EasyUiPage listItem(int page, int rows) {
		return itemService.findItemList(page, rows);
	}

	@RequestMapping("/save")
	public @ResponseBody TaotaoResult createItem(TbItem item, String desc, String itemParams) {
		TaotaoResult taotaoResult = itemService.createItem(item, desc, itemParams);
		if (200 == taotaoResult.getStatus()) {
			taotaoResult = itemService.addSearchIndex((TbItem) taotaoResult.getData());
		}

		return taotaoResult;
	}
}
